﻿using System;
using System.Collections.Generic;
using WinSource.Model.Helpers;

namespace WinSource.Model
{
    public class GroupArticleByDate : IEnumerable<Article>
    {
        public GroupArticleByDate(DateTime date, IEnumerable<Article> articles)
        {
            Date = date;
            Items = new List<Article>(articles);
        }

        public override bool Equals(object obj)
        {
            GroupArticleByDate that = obj as GroupArticleByDate;
            return (that != null) && (Date.Equals(that.Date));
        }

        public override int GetHashCode()
        {
            return Date.GetHashCode();
        }

        public DateTime Date { get; set; }
        public IList<Article> Items { get; set; }

        public string DateDifference
        {
            get
            {
                return DateHelper.GetDateDifferenceText(Date);
            }
        }

        public string ArticlesCountText
        {
            get { return string.Format("{0} article{1}", Items.Count, Items.Count > 1 ? "s" : ""); }
        }

        #region IEnumerable<T> Members

        public IEnumerator<Article> GetEnumerator()
        {
            return Items.GetEnumerator();
        }

        #endregion

        #region IEnumerable Members

        System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator()
        {
            return Items.GetEnumerator();
        }

        #endregion
    }
}